#ifndef STRATEGYCONTENXTBASE_H
#define STRATEGYCONTENXTBASE_H

#include <QObject>
#include "src/Strategypatttern/strategyconditionbase.h"
#include "src/Strategypatttern/threelevelconditiondetect.h"
#include "src/Strategypatttern/twolevelconditiondetect.h"
#include "src/Strategypatttern/onelevelconditiondetect.h"



class StrategyBase : public QObject
{

    Q_OBJECT
public:
    virtual void execute(conditionContext &context,NormalDetectBase &n, VerticalLengthDetectBase &v, FrequencyDetectBase &f, DirectLevelBase &d, BesideDetectBase &b,SteelInfo * steel) = 0;
public:
    int Level = 0;
};


//用于切换策略
class strategyContext : public QObject{
    Q_OBJECT

public:
    void SetStargy(StrategyBase *ctx){
        StrategyCtx = ctx;
    }


    /**不管什么等级都要进行5个条件的判断,例如: 一级缺陷需要对五个设定的条件进行缺陷等级设置
     * @brief execute
     * @param context
     * @param detectBase
     */
    void execute(conditionContext &context,NormalDetectBase &n, VerticalLengthDetectBase &v, FrequencyDetectBase &f, DirectLevelBase &d, BesideDetectBase &b,SteelInfo * steel){

        StrategyCtx->execute(context,n,v,f,d,b,steel);
    }


public:
    StrategyBase *StrategyCtx;
};


//判断缺陷等级1
class strategyDetectOneLevel : public StrategyBase{

public:
    int Level = 1;

    void execute(conditionContext &context,NormalDetectBase &n, VerticalLengthDetectBase &v, FrequencyDetectBase &f, DirectLevelBase &d, BesideDetectBase &b,SteelInfo * steel){

        //逻辑上来说 应该是在一级策略下检测完毕后根据返回值来确定是否继续判断二级以及三级

        context.SetStrategy(new OneLevelNormalDetectStrategy);
        context.execute(n,steel,this->Level);

        context.SetStrategy(new OneLevelBesideDetectStrategy);
        context.execute(b,steel,this->Level);

        context.SetStrategy(new OneLevelFrequencyDetectStrategy);
        context.execute(f,steel,this->Level);

        context.SetStrategy(new OneLevelVerticalLengthDetectStrategy);
        context.execute(v,steel,this->Level);
    }
};


//判断缺陷等级2
class strategyDetectTwoLevel : public StrategyBase{
public:
    int Level = 2;
    void execute(conditionContext &context,NormalDetectBase &n, VerticalLengthDetectBase &v, FrequencyDetectBase &f, DirectLevelBase &d, BesideDetectBase &b,SteelInfo * steel){

        context.SetStrategy(new TwoLevelNormalDetectStrategy);
        context.execute(n,steel,this->Level);

        context.SetStrategy(new TwoLevelBesideDetectStrategy);
        context.execute(b,steel,this->Level);

        context.SetStrategy(new TwoLevelFrequencyDetectStrategy);
        context.execute(f,steel,this->Level);

        context.SetStrategy(new TwoLevelVerticalLengthDetectStrategy);
        context.execute(v,steel,this->Level);
    }
};

//判断缺陷等级3
class startegyDetectThreeLevel : public StrategyBase{
public:
    int Level = 3;

    void execute(conditionContext &context,NormalDetectBase &n, VerticalLengthDetectBase &v, FrequencyDetectBase &f, DirectLevelBase &d, BesideDetectBase &b,SteelInfo * steel){

        context.SetStrategy(new ThreeLevelNormalDetectStrategy);
        context.execute(n,steel,this->Level);

        context.SetStrategy(new ThreeLevelBesideDetectStrategy);
        context.execute(b,steel,this->Level);

        context.SetStrategy(new ThreeLevelFrequencyDetectStrategy);
        context.execute(f,steel,this->Level);

        context.SetStrategy(new ThreeLevelVerticalLengthDetectStrategy);
        context.execute(v,steel,this->Level);

        context.SetStrategy(new ThreeLevelDirectDetectStrategy);
        context.execute(d,steel,this->Level);
    }
};








#endif // STRATEGYCONTENXTBASE_H
